home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / STAT / MULREG.PAS < prev    next >
Pascal/Delphi Source File  |  1990-08-05  |  3KB  |  73 lines

  1. program mul_reg_demo;
  2.  
  3. uses
  4.    crt,stat;
  5. const
  6.      num12 = 12;                       { number of data points }
  7. var
  8.    y,x,z,a : single_array_pointer;     { point to dynamic arrays }
  9.    j       : word;
  10.    r,se    : single;
  11.    mean,
  12.    small,y_est,
  13.    large,diff,
  14.    sd      : single;
  15.    a1,b1   : single;
  16. begin
  17. { create dynamic arrays}
  18.      create_single_array(num12,x);     { create x dynamic array }
  19.      create_single_array(num12,y);     { create y dynamic array }
  20.      create_single_array(num12,z);     { create z dynamic array }
  21.      create_single_array(3,a);         { create regression coef. array }
  22.  
  23. { put data into the arrays}
  24.      y^[1] := 110.0; x^[1] := 60.0; z^[1] := 40.0;
  25.      y^[2] := 135.0; x^[2] := 60.0; z^[2] := 20.0;
  26.      y^[3] := 120.0; x^[3] := 60.0; z^[3] := 30.0;
  27.      y^[4] := 120.0; x^[4] := 62.0; z^[4] := 20.0;
  28.      y^[5] := 140.0; x^[5] := 62.0; z^[5] := 30.0;
  29.      y^[6] := 130.0; x^[6] := 62.0; z^[6] := 40.0;
  30.      y^[7] := 135.0; x^[7] := 62.0; z^[7] := 20.0;
  31.      y^[8] := 150.0; x^[8] := 64.0; z^[8] := 30.0;
  32.      y^[9] := 145.0; x^[9] := 64.0; z^[9] := 30.0;
  33.      y^[10] := 170.0; x^[10] := 70.0; z^[10] := 20.0;
  34.      y^[11] := 185.0; x^[11] := 70.0; z^[11] := 30.0;
  35.      y^[12] := 160.0; x^[12] := 70.0; z^[12] := 40.0;
  36.  
  37. { clear screen and print header}
  38.      clrscr;
  39.      writeln('                       MULREG EXAMPLE');
  40.      writeln('            mean        sd     small    large');
  41.      writeln('           ------     ------   ------   ------');
  42. { get stats on each variable }
  43.      elem_stat(num12,x,small,large,mean,sd);
  44.      writeln('x data',mean:10:2,sd:10:2,small:10:2,large:10:2);
  45.      elem_stat(num12,z,small,large,mean,sd);
  46.      writeln('z data',mean:10:2,sd:10:2,small:10:2,large:10:2);
  47.      elem_stat(num12,y,small,large,mean,sd);
  48.      writeln('y data',mean:10:2,sd:10:2,small:10:2,large:10:2);
  49.      writeln;
  50. { run mulreg}
  51.      mulreg(num12,y,x,z,a,r,se);
  52.  
  53. { print out regression coefficients }
  54.          writeln('y estimated = ',a^[1]:10:5,' + ',a^[2]:10:5,' * X'
  55.                                             ,' + ',a^[3]:10:5,' * Z');
  56.  
  57. { print out correlation coefficient and standard error}
  58.      writeln('R = ',r:10:3,' standard error = ',se:20:10,' units');
  59. { print out estimations }
  60.      writeln('   actual   estimated   difference');
  61.      for j := 1 to num12 do
  62.      begin
  63.           y_est := a^[1] + (a^[2] * x^[j]) + (a^[3] * z^[j]);
  64.           diff  := y^[j] - y_est;
  65.           z^[j] := diff;
  66.           x^[j] := j;
  67.           writeln(y^[j]:10:3,y_est:10:3,diff:10:3);
  68.      end;
  69. { see if residuals are correlated }
  70.      linfit(num12,x,z,z,0,a1,b1,r);
  71.      writeln('intercept of residuls',a1:10:3,' slope =', b1:10:3,'  R= ',r:10:3,' Nope');
  72.  
  73. end.